package com.wanmait.recruit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.mapper.PositionMapper;
import com.wanmait.recruit.pojo.Position;
import com.wanmait.recruit.service.PositionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("positionService")
public class PositionServiceImp implements PositionService {
    @Resource
    private PositionMapper positionMapper;
    @Override
    public PageInfo<Position> findAll(String name, Integer typeId, Integer pageNum) {
        int pageSize = 10;
        PageHelper.startPage(pageNum,pageSize);
        List<Position> positions = positionMapper.findAll(name,typeId);
        PageInfo<Position> pageInfo = new PageInfo<>(positions,11);
        return pageInfo;
    }

    @Override
    public void delete(Integer id) {
        positionMapper.deleteById(id);
    }

    @Override
    public Boolean isRename(String name) {
        Position position = positionMapper.findByPositionName(name);
        if(position==null){
            return true;
        }
        else {
            return false;
        }
    }

    @Override
    public String selectByPositionTypeId(Integer positionId) {
        Position position = positionMapper.selectByPrimaryKey(positionId);
        return position.getPositionName();
    }

    @Override
    public ArrayList<Position> selectFindAll() {
        return positionMapper.findAll2();
    }

    @Override
    public List<Position> selectALLByPositionTypeId(Integer id) {
        return positionMapper.selectALLByPositionTypeId(id);
    }

    @Override
    public void insert(Position object) {
        positionMapper.insert(object);
    }

    @Override
    public void delete(Position object) {

    }

    @Override
    public void update(Position object) {

    }

    @Override
    public PageInfo<Position> search(int pageNum, int pageSize) {
        return null;
    }
}
